package com.thuan.android3d;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import javax.microedition.khronos.opengles.GL10;

public class Triangle1 {

	private FloatBuffer floatBuffer;
		
	

	public Triangle1() {
		initialize();		
	}

	public void initialize() {

		float vertices[] = { 
				-0.7f, -0.7f, 0.0f, // V1 - first vertex
				0.7f, -0.7f, 0.0f, // V2 - second vertex
				0.0f, 0.7f, 0.0f // V3 - third vertex
		};
		
		ByteBuffer bbb=ByteBuffer.allocateDirect(vertices.length*4);
		bbb.order(ByteOrder.nativeOrder());
		floatBuffer=bbb.asFloatBuffer();
		
		floatBuffer.put(vertices);
		floatBuffer.position(0);
		
	}

	public void onDrawGL(GL10 gl) {
		gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
		
		gl.glColor4f(1.0f, 0.0f, 0.0f, 0.5f);
		
		gl.glVertexPointer(3, GL10.GL_FLOAT, 0, floatBuffer);
		
		gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0,3);
		
		gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
	}
	
}
